import type {
  GetCodeData,
  GetCodeParams,
  PostLoginCodeParams,
  PostLoginData,
  PostLoginPasswordParams,
  PostPatientConsultOrderParams,
  PostUploadData,
} from '@/types/common'
import { request, service } from '@/utils/request'

/**
 * 登录--密码登录
 * @param data
 * @returns
 */
export const postLoginPasswordAPI = (data: PostLoginPasswordParams) => {
  return request<PostLoginData>('/login/password', 'POST', data)
}

/**
 * 获取手机验证码
 * @param params
 * @returns
 */
export const getCodeAPI = (params: GetCodeParams) => {
  return request<GetCodeData>('/code', 'GET', params)
}

/**
 * 登录--短信登录
 * @param data
 * @returns
 */
export const postLoginAPI = (data: PostLoginCodeParams) => {
  return request<PostLoginData>('/login', 'POST', data)
}

// 能兼容多端的上传写法 ✅
export const postUploadAPI = (filePath: string) => {
  // 底层调用的是 uni.uploadFile() 兼容多端
  return request<PostUploadData>(
    '/upload',
    'UPLOAD',
    {},
    {
      name: 'file', // 后端参数对应的 key
      filePath: filePath, // 要上传文件资源的路径
    }
  )
}

// 问诊-保存/修改问诊订单
// POST
// /patient/consult/order
export const postPatientConsultOrderAPI = (data: PostPatientConsultOrderParams) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}
